package com.ruoyi.smartcity.park.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.smartcity.park.domain.ParkJiaofeiinfo;
import com.ruoyi.smartcity.park.mapper.ParkJiaofeiinfoMapper;
import com.ruoyi.smartcity.park.service.IParkJiaofeiinfoService;
import com.ruoyi.smartcity.traffic.vo.EchartsOptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 缴费信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@Service
public class ParkJiaofeiinfoServiceImpl implements IParkJiaofeiinfoService 
{
    @Autowired
    private ParkJiaofeiinfoMapper parkJiaofeiinfoMapper;

    /**
     * 查询缴费信息
     * 
     * @param id 缴费信息主键
     * @return 缴费信息
     */
    @Override
    public ParkJiaofeiinfo selectParkJiaofeiinfoById(Long id)
    {
        return parkJiaofeiinfoMapper.selectParkJiaofeiinfoById(id);
    }

    /**
     * 查询缴费信息列表
     * 
     * @param parkJiaofeiinfo 缴费信息
     * @return 缴费信息
     */
    @Override
    public List<ParkJiaofeiinfo> selectParkJiaofeiinfoList(ParkJiaofeiinfo parkJiaofeiinfo)
    {
        return parkJiaofeiinfoMapper.selectParkJiaofeiinfoList(parkJiaofeiinfo);
    }

    /**
     * 新增缴费信息
     * 
     * @param parkJiaofeiinfo 缴费信息
     * @return 结果
     */
    @Override
    public int insertParkJiaofeiinfo(ParkJiaofeiinfo parkJiaofeiinfo)
    {
        parkJiaofeiinfo.setCreateTime(DateUtils.getNowDate());
        return parkJiaofeiinfoMapper.insertParkJiaofeiinfo(parkJiaofeiinfo);
    }

    /**
     * 修改缴费信息
     * 
     * @param parkJiaofeiinfo 缴费信息
     * @return 结果
     */
    @Override
    public int updateParkJiaofeiinfo(ParkJiaofeiinfo parkJiaofeiinfo)
    {
        parkJiaofeiinfo.setUpdateTime(DateUtils.getNowDate());
        return parkJiaofeiinfoMapper.updateParkJiaofeiinfo(parkJiaofeiinfo);
    }

    /**
     * 批量删除缴费信息
     * 
     * @param ids 需要删除的缴费信息主键
     * @return 结果
     */
    @Override
    public int deleteParkJiaofeiinfoByIds(Long[] ids)
    {
        return parkJiaofeiinfoMapper.deleteParkJiaofeiinfoByIds(ids);
    }

    /**
     * 删除缴费信息信息
     * 
     * @param id 缴费信息主键
     * @return 结果
     */
    @Override
    public int deleteParkJiaofeiinfoById(Long id)
    {
        return parkJiaofeiinfoMapper.deleteParkJiaofeiinfoById(id);
    }

    @Override
    public EchartsOptionVO cheweiTrend() {
        EchartsOptionVO vo = new EchartsOptionVO();
        JSONArray yData = new JSONArray();
        JSONArray xData = new JSONArray();
        // 获取最近7天的日期
        List<String> days = new ArrayList<>();
        for (int i = 0; i < 7; i++) {
            String day = DateUtil.formatDate(DateUtil.offsetDay(DateUtil.date(), -(6 - i)));
            days.add(day);
            xData.add(day);
        }
        vo.setXData(xData);
        for (String day : days){
           int count = parkJiaofeiinfoMapper.cheweiTrend(day);
           yData.add(count);
        }
        vo.setYData(yData);
        return vo;
    }
}
